package com.itheima.homework.assignment.Test01;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 有4个人参加公务员考试,考试成绩如图所示,录取3名学生,淘汰分数最低的一名,设计一个程序,完成需求
 */
public class Test {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student(1,"小亮",99));
        students.add(new Student(2, "小强", 85));
        students.add(new Student(3, "小响", 90));
        students.add(new Student(4, "小勇", 75));

        double min = students.get(0).getScore(); //最低分
        int index = 0; //最低分的学生的索引值

        for (int i = 0; i < students.size(); i++) {
            if (students.get(i).getScore() < min) {
                min = students.get(i).getScore();
                index = i;
            }
        }
        students.remove(index);

        double sum = 0; //总分
        for (Student student : students) {
            sum += student.getScore();
        }
        double average = sum / 3;
        System.out.println("average = " + average);
    }
}
